package com.xyc.gulimall.product.app;

import com.xyc.common.utils.PageUtils;
import com.xyc.common.utils.R;
import com.xyc.gulimall.product.entity.SpuInfoEntity;
import com.xyc.gulimall.product.service.SpuInfoService;
import com.xyc.gulimall.product.vo.SpuSaveVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


/**
 * spu信息
 *
 * @author xyc
 * @email xyc@gmail.com
 * @date 2024-07-15 18:22:53
 */
@RestController
@RequestMapping("product/spuinfo")
public class SpuInfoController {
    @Autowired
    private SpuInfoService spuInfoService;

    @GetMapping("/skuId/{id}")
    public R getSpuInfoBySkuId(@PathVariable("id") Long skuId){
        SpuInfoEntity spuInfoEntity = spuInfoService.getSpuInfoBySkuId(skuId);
        return R.ok().put("data",spuInfoEntity);
    }

    /**
     * 商品上架
     *
     * @param spuId
     * @return
     */
    ///product/spuinfo/{spuId}/up
    @PostMapping("/{spuId}/up")
    public R spuUp(@PathVariable Long spuId) {
        spuInfoService.up(spuId);
        return R.ok();
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("product:spuinfo:list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = spuInfoService.queryPageByCondition(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("product:spuinfo:info")
    public R info(@PathVariable("id") Long id) {
        SpuInfoEntity spuInfo = spuInfoService.getById(id);

        return R.ok().put("spuInfo", spuInfo);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("product:spuinfo:save")
    public R save(@RequestBody SpuSaveVo spuSaveVo) {
        System.out.println("发布商品：" + spuSaveVo);
        //spuInfoService.save(spuInfo);
        spuInfoService.saveSpuInfo(spuSaveVo);

        /*
          SpuSaveVo(
          spuName=23,
          spuDescription=123,
          catalogId=225,
          brandId=14,
          weight=0.123,
          publishStatus=0,
          decript=[https://gulimall-xieyuancheng.oss-cn-shenzhen.aliyuncs.com/2024-08-16/7e88f126-df42-4014-8b62-c6a47cfcbc92_0d40c24b264aa511.jpg],
          images=[
          https://gulimall-xieyuancheng.oss-cn-shenzhen.aliyuncs.com/2024-08-16/55fa8184-8d03-4250-890a-1cca9cf9a3f8_6a1b2703a9ed8737.jpg,
          https://gulimall-xieyuancheng.oss-cn-shenzhen.aliyuncs.com/2024-08-16/22047f61-22d7-4281-8bf2-0b3fa294d1fc_5b5e74d0978360a1.jpg],
          bounds=Bounds(buyBounds=100, growBounds=100),
          baseAttrs=[
          BaseAttrs(attrId=7, attrValues=2018, showDesc=1),
          BaseAttrs(attrId=8, attrValues=4G, showDesc=1),
          BaseAttrs(attrId=12, attrValues=黑色, showDesc=1),
          BaseAttrs(attrId=13, attrValues=158.3, showDesc=1),
          BaseAttrs(attrId=14, attrValues=陶瓷;以官网信息为准, showDesc=1),
          BaseAttrs(attrId=15, attrValues=高通, showDesc=1),
          BaseAttrs(attrId=16, attrValues=骁龙888, showDesc=1)],
          skus=[
          Skus(
          attr=[
          Attr(attrId=10, attrName=颜色, attrValue=黑色),
          Attr(attrId=11, attrName=内存, attrValue=8GB)],
          skuName=23 黑色 8GB,
          price=12,
          skuTitle=23 黑色 8GB,
          skuSubtitle=123,
          images=[
          Images(
          imgUrl=https://gulimall-xieyuancheng.oss-cn-shenzhen.aliyuncs.com/2024-08-16/55fa8184-8d03-4250-890a-1cca9cf9a3f8_6a1b2703a9ed8737.jpg,
          defaultImg=1),
          Images(
          imgUrl=https://gulimall-xieyuancheng.oss-cn-shenzhen.aliyuncs.com/2024-08-16/22047f61-22d7-4281-8bf2-0b3fa294d1fc_5b5e74d0978360a1.jpg,
          defaultImg=0)],
          descar=[黑色, 8GB],
          fullCount=0,
          discount=0,
          countStatus=0,
          fullPrice=0,
          reducePrice=0,
          priceStatus=0,
          memberPrice=[
          MemberPrice(id=2, name=铜牌会员, price=0),
          MemberPrice(id=3, name=银牌会员, price=0)]),
          Skus(
          attr=[
          Attr(attrId=10, attrName=颜色, attrValue=黑色),
          Attr(attrId=11, attrName=内存, attrValue=12GB)],
          skuName=23 黑色 12GB,
          price=21,
          skuTitle=23 黑色 12GB,
          skuSubtitle=123,
          images=[
          Images(imgUrl=https://gulimall-xieyuancheng.oss-cn-shenzhen.aliyuncs.com/2024-08-16/55fa8184-8d03-4250-890a-1cca9cf9a3f8_6a1b2703a9ed8737.jpg, defaultImg=1),
          Images(imgUrl=https://gulimall-xieyuancheng.oss-cn-shenzhen.aliyuncs.com/2024-08-16/22047f61-22d7-4281-8bf2-0b3fa294d1fc_5b5e74d0978360a1.jpg, defaultImg=0)],
          descar=[黑色, 12GB],
          fullCount=0,
          discount=0,
          countStatus=0,
          fullPrice=0,
          reducePrice=0,
          priceStatus=0,
          memberPrice=[
          MemberPrice(id=2, name=铜牌会员, price=0),
          MemberPrice(id=3, name=银牌会员, price=0)]),
          Skus(attr=[
          Attr(attrId=10, attrName=颜色, attrValue=白色),
          Attr(attrId=11, attrName=内存, attrValue=8GB)],
          skuName=23 白色 8GB,
          price=12,
          skuTitle=23 白色 8GB,
          skuSubtitle=123,
          images=[
          Images(imgUrl=https://gulimall-xieyuancheng.oss-cn-shenzhen.aliyuncs.com/2024-08-16/55fa8184-8d03-4250-890a-1cca9cf9a3f8_6a1b2703a9ed8737.jpg, defaultImg=0),
          Images(imgUrl=https://gulimall-xieyuancheng.oss-cn-shenzhen.aliyuncs.com/2024-08-16/22047f61-22d7-4281-8bf2-0b3fa294d1fc_5b5e74d0978360a1.jpg, defaultImg=1)],
          descar=[白色, 8GB],
          fullCount=0,
          discount=0,
          countStatus=0,
          fullPrice=0,
          reducePrice=0,
          priceStatus=0,
          memberPrice=[
          MemberPrice(id=2, name=铜牌会员, price=0),
          MemberPrice(id=3, name=银牌会员, price=0)]),
          Skus(
          attr=[Attr(attrId=10, attrName=颜色, attrValue=白色),Attr(attrId=11, attrName=内存, attrValue=12GB)],
          skuName=23 白色 12GB, price=21, skuTitle=23 白色 12GB,
          skuSubtitle=123,
          images=[
          Images(imgUrl=https://gulimall-xieyuancheng.oss-cn-shenzhen.aliyuncs.com/2024-08-16/55fa8184-8d03-4250-890a-1cca9cf9a3f8_6a1b2703a9ed8737.jpg, defaultImg=0),
          Images(imgUrl=https://gulimall-xieyuancheng.oss-cn-shenzhen.aliyuncs.com/2024-08-16/22047f61-22d7-4281-8bf2-0b3fa294d1fc_5b5e74d0978360a1.jpg, defaultImg=1)],
          descar=[白色, 12GB],
          fullCount=0,
          discount=0,
          countStatus=0,
          fullPrice=0,
          reducePrice=0,
          priceStatus=0,
          memberPrice=[
          MemberPrice(id=2, name=铜牌会员, price=0),
          MemberPrice(id=3, name=银牌会员, price=0)])])
         */
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("product:spuinfo:update")
    public R update(@RequestBody SpuInfoEntity spuInfo) {
        spuInfoService.updateById(spuInfo);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("product:spuinfo:delete")
    public R delete(@RequestBody Long[] ids) {
        spuInfoService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
